package jdbc.lessen03;


import jdbc.lessen02.util.JdbcUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Package lessen03
 * @Author shimmer
 * @Date 2020/7/31 11:56
 * @TODO
 */
public class PreSelect {
    public static void main(String[] args) {
        ResultSet rs=null;
        Connection conn=null;
        PreparedStatement ps = null;
        try {
            conn = JdbcUtil.getConnection();
            //区别
            String sql="select `name` from `user` where `id`=?";
            ps = conn.prepareStatement(sql);//预编译sql，不执行
            //手动填写参数
            ps.setInt(1,1);
            rs = ps.executeQuery();//执行
            while (rs.next()) {
                System.out.println(rs.getString(1));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JdbcUtil.release(rs, ps, conn);
        }
    }
}
